package com.plm.maque.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.plm.maque.dao.ImageInfoMapper;
import com.plm.maque.entity.ImageInfo;
import com.plm.maque.service.ImageInfoService;
import com.plm.maque.utils.PageUtils;
import com.plm.maque.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author Limi
 * @create 2019-04-21 17:29
 */
@Service
public class ImageInfoServiceImpl extends ServiceImpl<ImageInfoMapper, ImageInfo> implements ImageInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        long current = params.get("current") == null ? 1 : Long.valueOf((String) params.get("current"));
        long size = params.get("size") == null ? 10 : Long.valueOf((String) params.get("size"));

        Page<ImageInfo> pages = (Page<ImageInfo>) this.page(
                new Page<>(current, size),
                new QueryWrapper<>()
        );

        return new PageUtils(pages);
    }

    @Override
    public boolean saveImageInfo(ImageInfo imageInfo) {
        return save(imageInfo);
    }

    @Override
    public ImageInfo getImageInfo(Map<String, Object> params) {
        String id = (String) params.get("id");

        ImageInfo imageInfo = this.getOne(new QueryWrapper<ImageInfo>()
                .eq(StringUtils.isNotNull(id), "id", id)
        );
        return imageInfo;
    }
}
